#include "Arduino.h"

/*
 * https://wokwi.com/projects/332576245745189459
  程序： FREERTOS - 多任务点灯程序实例
  作业： 添加LED3
  公众号：孤独的二进制
*/
void task1(void *pt) {
    pinMode(23, OUTPUT);
    while (1) {
        digitalWrite(23, !digitalRead(23));
        /*
          Tick to Time
            pdMS_TO_TICKS
            portTICK_PERIOD_MS
          vTaskDelay(pdMS_TO_TICKS(1000));
          vTaskDelay(1000/portTICK_PERIOD_MS);
        */
        vTaskDelay(1000); //注意 是 ticks的数量 不是时间
    }
}

void task2(void *pt) {
    pinMode(21, OUTPUT);
    while (1) {
        digitalWrite(21, !digitalRead(21));
        vTaskDelay(3000);
    }
}


void setup() {
    Serial.begin(9600);
    Serial.print("MIngESP32 Tick Period - ");
    Serial.print(portTICK_PERIOD_MS);
    Serial.println("ms");

    if (xTaskCreate(task1,
                    "Blink 23",
                    1024,
                    NULL,
                    1,
                    NULL) == pdPASS)
        Serial.println("Task1 Created.");

    if (xTaskCreate(task2,
                    "Blink 21",
                    1024,
                    NULL,
                    1,
                    NULL) == pdPASS)
        Serial.println("Task2 Created.");


}

void loop() {
}